﻿using System;
using System.Collections.Generic;
using Circa.Tools;
using Configuration = Circa.Configuration;

namespace Circa.Protocol.Irc {

    public class User: ITargetable {
        // config properties
        public string Name { get; set; }
        public string Description { get; set; }

        public List<string> Nicks { get; set; }
        public string UserName { get; set; }
        public string HostName { get; set; }
        public string RealName { get; set; }

        // other properties
        public Network Network { get; set; }
        public Server Server { get; set; }
        public IList<Channel> Channels { get; set; }

        protected SafeDictionary<string, Action<IrcMessage>> verbs = new SafeDictionary<string, Action<IrcMessage>>( );

        protected User( ) {
            Nicks = new List<string>( );
            Channels = new List<Channel>( );
        }

        public User( Network _network, Configuration.Identity conf ) {
            Network = _network;

            Name = conf.Name;
            Description = conf.Description;

            Nicks = new List<string>( conf.Nicks );
            UserName = conf.UserName;
            HostName = conf.HostName;
            RealName = conf.RealName;
        }

        public virtual bool Dispatch( IrcMessage m ) {
            Action<IrcMessage> handler = verbs[ m.Verb ];
            if ( null != handler ) {
                handler( m );
                return true;
            }
            return false;
        }

    }

}
